<?php
class RedisManager {
    private $redis;

    public function __construct() {
        $this->redis = new Redis();
        $this->redis->connect('127.0.0.1', 6379);
    }

    public function getConnection() {
        return $this->redis;
    }

    public function setGameData($gameId, $key, $value) {
        return $this->redis->hSet("game:{$gameId}", $key, json_encode($value));
    }

    public function getGameData($gameId, $key) {
        $data = $this->redis->hGet("game:{$gameId}", $key);
        return $data ? json_decode($data, true) : null;
    }

    public function deleteGame($gameId) {
        return $this->redis->del("game:{$gameId}");
    }
}
?>